package com.temi.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.temi.demo.anim.EasyTransition;
import com.temi.demo.anim.EasyTransitionOptions;

import butterknife.ButterKnife;
import butterknife.Unbinder;


public abstract class BaseActivity extends AppCompatActivity {

    public static final String KEY_BUNDLE = "bundle";
    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayout());

        unbinder = ButterKnife.bind(this);

        initTitle();
        initData();
        initView(savedInstanceState);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }

    public abstract int getLayout();

    protected void initTitle() {}

    protected abstract void initData();

    protected abstract void initView(Bundle savedInstanceState);

    public void startAction(Class<?> cl, Bundle bundle) {
        Intent intent = new Intent(this, cl);
        if (bundle != null) {
            intent.putExtra(KEY_BUNDLE, bundle);
        }
        startActivity(intent);
    }

    public void startAction(Class<?> cl, Bundle bundle, EasyTransitionOptions options) {
        Intent intent = new Intent(this, cl);
        if (bundle != null) {
            intent.putExtra(KEY_BUNDLE, bundle);
        }

        EasyTransition.startActivity(intent, options);
    }
}
